﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;
using WcfContrib.Extensions.Caching;

namespace Contracts
{
    [ServiceContract(Name = "IService")]
    interface IService1
    {
        [OperationContract]
        Foo GetFoo(Foo[] foos);
    }

    //NOTE:
    //You can use the output cache attribute on the service level as well
    //It will set the output cache for all operations who don't have one explicitly set on them
    //You may want to look into all the options of the output caching (policy, ignore default value, compare enumerable items, custom provider factory)
    //IN ADDITION:
    //The output cache behavior can be set per-instance of the Client Channel or define it on your own wrapper. (See Extensions sample and docs in CodePlex)
    [ServiceContract(Name = "IService")]
    interface IService2
    {
        [OperationContract]
        [OutputCacheBehavior(OutputCachePolicy.Absolute, 3000)]
        //[OutputCacheBehavior(OutputCachePolicy.Sliding, 3000)]
        Foo GetFoo(Foo[] foos);
    }

    [DataContract]
    public class Foo
    {
        [DataMember]
        public int Id { get; set; }

        [DataMember]
        public string Name { get; set; }

        public override bool Equals(object obj)
        {
            return Id.Equals(((Foo)obj).Id);
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }
    }
}
